import express from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import cookieSession from 'cookie-session';

//引入保安大爷
import {router} from './routes/apiRouter'

const app = express();

//配置中间件
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.use(cookieParser("useker.cn"));
app.use(cookieSession({
	name:"useker.cn",
	keys:["aa","bb","cc"],
	expires:1000 * 60 * 20
}));

//拦截器
app.all("*",(req,res,next) => {
	res.header("Content-Type","application/json;charset=utf-8");
	res.header("Access-Control-Allow-Origin","*");
	
	next();
})

//配置路由
app.use("/api",router);


app.listen(8080,() => {
	console.log("服务器启动完毕...")
})